Skip to content

feat: allow returning multiple values as tuples instead of lists#551

Draft
dlech wants to merge 5 commits intomainfrom
return-tuples-not-lists
Draft

feat: allow returning multiple values as tuples instead of lists#551
dlech wants to merge 5 commits intomainfrom
return-tuples-not-lists

Conversation

@dlech
Copy link
Member

@dlech dlech commented Nov 17, 2025

In Python, the natural way to return multiple values from a function is
as a tuple. Change the docs to recommend returning tuples instead of lists
for D-Bus methods and signals that return multiple values.

Tests are updated as well to show that tuples are preferred (and that
this is not a breaking change).

In Python, the natural way to return multiple values from a function is
as a tuple. Change the docs to recommend returning tuples instead of lists
for D-Bus methods and signals that return multiple values.

Tests are updated as well to show that tuples are preferred (and that
this is not a breaking change).
@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.31%. Comparing base (d4389e5) to head (f5f79bd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #551      +/-   ##
==========================================
+ Coverage   85.26%   85.31%   +0.05%     
==========================================
  Files          28       28              
  Lines        3433     3433              
  Branches      601      601              
==========================================
+ Hits         2927     2929       +2     
+ Misses        313      312       -1     
+ Partials      193      192       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 17, 2025

CodSpeed Performance Report

Merging #551 will not alter performance

Comparing return-tuples-not-lists (f5f79bd) with main (d4389e5)

Summary

✅ 6 untouched

@dlech
Copy link
Member Author

dlech commented Nov 17, 2025

Interesting, it breaks Cython. Was not expecting that. It may be a breaking change after all.

@dlech
Copy link
Member Author

dlech commented Nov 17, 2025

Well, not breaking in the semver sense since we aren't changing the library itself. But rather would be a feature to allow Cython to accept tuple in addition to list.

@dlech dlech changed the title chore: recommend returning multiple values as tuples instead of lists feat: allow returning multiple values as tuples instead of lists Nov 17, 2025
@dlech dlech marked this pull request as draft November 17, 2025 05:38
@dlech
Copy link
Member Author

dlech commented Nov 17, 2025

I'll have to think about this some more.

There are two sides to this, only one of which has been addressed so far.

The first is relaxing the allowable types for body as an input. This is what has been done here so far. Other than the one type change for Cython that is needed to make it work at runtime, it is just a matter of type hints. I've made everything list[Any] | tuple[Any, ...], but that is rather verbose and we could actually replace it with Sequence[Any] (from collections.abc).

The part I haven't addressed though is that I've just realized that in addition to #526 there is also the case where returning multiple values should also be implemented as a tuple to allow for correct type hints. However, it is currently implemented as a list. Where this matters is for proxy types. We likely need it to be a list when unmarshalling messages to avoid issues with tuple immutability, i.e. a performance cost for having to create a new tuple object every time we unmarshal the next element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments